package com.ethannhu.todaynews.adapter

import android.content.Context
import androidx.fragment.app.Fragment
import androidx.fragment.app.FragmentManager
import androidx.fragment.app.FragmentStatePagerAdapter
import com.ethannhu.todaynews.component.guide.GuideFragment

/**
 * BaseFragmentPagerAdapter
 * 主要是创建了列表实现了通用的方法
 * 直接用FragmentPagerAdapter有可能有内存泄漏
 * 所以使用FragmentStatePagerAdapten
 */
abstract class BaseFragmentPagerAdapter<T>(val context: Context, fragmentManager: FragmentManager)
    : FragmentStatePagerAdapter(fragmentManager) {
    private var datum: MutableList<T> = mutableListOf()

    override fun getCount(): Int {
        return datum.size
    }

    fun setDatum(datum: MutableList<T>) {
        this.datum.clear()
        this.datum.addAll(datum)
        notifyDataSetChanged()
    }

    protected fun getData(position: Int): T {
        return datum[position]
    }


}